*** Settings ***
Library           FN

*** Test Cases ***
2.1 用户当年存在一个无需结算的账单，通过接口查询一个未结算账单（limit为1），返回为空
    Init Step
    ${interface}    Set Variable    cn.com.servyou.business.obc.facade.BillQueryFacade
    ${method}    Set Variable    getUnsettleBill
    ${customerId}    Get UUID
    ${serviceType}    Set Variable    ${PTS_INFO['serviceTypeName']}
    ${year}    Set Variable    2020
    ${month}    Set Variable    9
    ${limit}    Set Int Variable    1
    Redis Step
    Connect To Redis    ${OBC_REDIS_URL}    ${OBC_REDIS_ALIAS}
    ${redis_key}    Get Obc Unsettle Bill Key    ${customerId}    ${PTS_INFO['serviceType']}    ${limit}
    Delete Key From Redis    ${OBC_REDIS_ALIAS}    ${redis_key}
    Mysql Step
    ${new_bill_sql}    Create Oec Bill    ${OBC_BILL_NONEED}    ${customerId}    ${year}    ${month}
    Connect To Database    pymysql    ${OBC_DB_URL}    ${OBC_DB_ALIAS}
    Execute Sql String    ${OBC_DB_ALIAS}    DELETE from obc_fee_bill where customer_id = '${customer_id}'    ${DB_OP_TYPE_DELETE}
    Execute Sql String    ${OBC_DB_ALIAS}    ${new_bill_sql}    ${DB_OP_TYPE_DELETE}
    Doing Step
    ${post_data}    Create Dictionary
    Set To Dictionary    ${post_data}    customerId    ${customerId}
    Set To Dictionary    ${post_data}    serviceType    ${serviceType}
    Set To Dictionary    ${post_data}    limit    ${limit}
    ${resp}    Dubbo Invoke    ${OBC_ZK_ADDR}    ${interface}    ${method}    ${post_data}    ${DUBBO_PAMAR_STRING}
    Check Step
    Redis Key Should Be Exist    ${OBC_REDIS_ALIAS}    ${redis_key}    30
    Length Should Be    ${resp['list']}    0
    Validate Schema    ${resp}
    Close Step
    Close Database    ${OBC_DB_ALIAS}
    Close Redis    ${OBC_REDIS_ALIAS}

2.2 用户当年存在一个未结算的账单，通过接口查询一个未结算账单（limit为1），返回该账单数据，结算截止时间为次月16日
    Init Step
    ${interface}    Set Variable    cn.com.servyou.business.obc.facade.BillQueryFacade    #接口名
    ${method}    Set Variable    getUnsettleBill    #方法名
    ${customerId}    Get UUID    # 获取每个用例对应的customerId
    ${serviceType}    Set Variable    ${PTS_INFO['serviceTypeName']}    # 平台类型
    ${year}    Set Variable    2020    # 账单年份
    ${month}    Set Variable    1    # 账单月份
    ${limit}    Set Int Variable    1    # 账单数量
    ${settleDeadline}    Get Bill Settle Day    ${year}    ${month}    # 获取最终结算时间
    ${new_bill_sql}    Create Oec Bill    ${OBC_BILL_UNSETTLE}    ${customerId}    ${year}    ${month}
    Redis Step
    Connect To Redis    ${OBC_REDIS_URL}    ${OBC_REDIS_ALIAS}
    ${redis_key}    Get Obc Unsettle Bill Key    ${customerId}    ${PTS_INFO['serviceType']}    ${limit}
    Delete Key From Redis    ${OBC_REDIS_ALIAS}    ${redis_key}
    Mysql Step
    Connect To Database    pymysql    ${OBC_DB_URL}    ${OBC_DB_ALIAS}
    Execute Sql String    ${OBC_DB_ALIAS}    DELETE from obc_fee_bill where customer_id = '${customer_id}'    ${DB_OP_TYPE_DELETE}
    Execute Sql String    ${OBC_DB_ALIAS}    ${new_bill_sql}    ${DB_OP_TYPE_DELETE}
    Doing Step
    ${post_data}    Create Dictionary
    Set To Dictionary    ${post_data}    customerId    ${customerId}
    Set To Dictionary    ${post_data}    serviceType    ${serviceType}
    Set To Dictionary    ${post_data}    limit    ${limit}
    ${resp}    Dubbo Invoke    ${OBC_ZK_ADDR}    ${interface}    ${method}    ${post_data}    ${DUBBO_PAMAR_STRING}
    Check Step
    Redis Key Should Be Exist    ${OBC_REDIS_ALIAS}    ${redis_key}
    Length Should Be    ${resp['list']}    1
    ${bill}    Set Variable    ${resp['list'][0]}
    Equal As String    ${bill['settleDeadline']}    ${settleDeadline}
    ${bill_check_sql}    Check Bill Sql    ${bill}
    Row Count Is Equal To X    ${OBC_DB_ALIAS}    ${bill_check_sql}    1
    Validate Schema    ${resp}
    Close Step
    Close Database    ${OBC_DB_ALIAS}
    Close Redis    ${OBC_REDIS_ALIAS}

2.3 用户当年存在一个已结算的账单，通过接口查询一个未结算账单（limit为1），返回为空
    Init Step
    ${interface}    Set Variable    cn.com.servyou.business.obc.facade.BillQueryFacade
    ${method}    Set Variable    getUnsettleBill
    ${customerId}    Get UUID
    ${serviceType}    Set Variable    ${PTS_INFO['serviceTypeName']}
    ${year}    Set Variable    2020
    ${month}    Set Variable    9
    ${limit}    Set Int Variable    1
    Redis Step
    Connect To Redis    ${OBC_REDIS_URL}    ${OBC_REDIS_ALIAS}
    ${redis_key}    Get Obc Unsettle Bill Key    ${customerId}    ${PTS_INFO['serviceType']}    ${limit}
    Delete Key From Redis    ${OBC_REDIS_ALIAS}    ${redis_key}
    Mysql Step
    ${new_bill_sql}    Create Oec Bill    ${OBC_BILL_SETTLED}    ${customerId}    ${year}    ${month}
    Connect To Database    pymysql    ${OBC_DB_URL}    ${OBC_DB_ALIAS}
    Execute Sql String    ${OBC_DB_ALIAS}    DELETE from obc_fee_bill where customer_id = '${customer_id}'    ${DB_OP_TYPE_DELETE}
    Execute Sql String    ${OBC_DB_ALIAS}    ${new_bill_sql}    ${DB_OP_TYPE_DELETE}
    Doing Step
    ${post_data}    Create Dictionary
    Set To Dictionary    ${post_data}    customerId    ${customerId}
    Set To Dictionary    ${post_data}    serviceType    ${serviceType}
    Set To Dictionary    ${post_data}    limit    ${limit}
    ${resp}    Dubbo Invoke    ${OBC_ZK_ADDR}    ${interface}    ${method}    ${post_data}    ${DUBBO_PAMAR_STRING}
    Check Step
    Redis Key Should Be Exist    ${OBC_REDIS_ALIAS}    ${redis_key}    30
    Length Should Be    ${resp['list']}    0
    Validate Schema    ${resp}
    Close Step
    Close Database    ${OBC_DB_ALIAS}
    Close Redis    ${OBC_REDIS_ALIAS}

2.4 用户当年存在一个已逾期的账单，通过接口查询一个未结算账单（limit为1），返回该账单数据，结算截止时间为次月16日
    Init Step
    ${interface}    Set Variable    cn.com.servyou.business.obc.facade.BillQueryFacade    #接口名
    ${method}    Set Variable    getUnsettleBill    #方法名
    ${customerId}    Get UUID    # 获取每个用例对应的customerId
    ${serviceType}    Set Variable    ${PTS_INFO['serviceTypeName']}    # 平台类型
    ${year}    Set Variable    2020    # 账单年份
    ${month}    Set Variable    1    # 账单月份
    ${limit}    Set Int Variable    1    # 账单数量
    ${settleDeadline}    Get Bill Settle Day    ${year}    ${month}    # 获取最终结算时间
    ${new_bill_sql}    Create Oec Bill    ${OBC_BILL_OVERDUED}    ${customerId}    ${year}    ${month}
    Redis Step
    Connect To Redis    ${OBC_REDIS_URL}    ${OBC_REDIS_ALIAS}
    ${redis_key}    Get Obc Unsettle Bill Key    ${customerId}    ${PTS_INFO['serviceType']}    ${limit}
    Delete Key From Redis    ${OBC_REDIS_ALIAS}    ${redis_key}
    Mysql Step
    Connect To Database    pymysql    ${OBC_DB_URL}    ${OBC_DB_ALIAS}
    Execute Sql String    ${OBC_DB_ALIAS}    DELETE from obc_fee_bill where customer_id = '${customer_id}'    ${DB_OP_TYPE_DELETE}
    Execute Sql String    ${OBC_DB_ALIAS}    ${new_bill_sql}    ${DB_OP_TYPE_DELETE}
    Doing Step
    ${post_data}    Create Dictionary
    Set To Dictionary    ${post_data}    customerId    ${customerId}
    Set To Dictionary    ${post_data}    serviceType    ${serviceType}
    Set To Dictionary    ${post_data}    limit    ${limit}
    ${resp}    Dubbo Invoke    ${OBC_ZK_ADDR}    ${interface}    ${method}    ${post_data}    ${DUBBO_PAMAR_STRING}
    Check Step
    Redis Key Should Be Exist    ${OBC_REDIS_ALIAS}    ${redis_key}
    Length Should Be    ${resp['list']}    1
    ${bill}    Set Variable    ${resp['list'][0]}
    Equal As String    ${bill['settleDeadline']}    ${settleDeadline}
    ${bill_check_sql}    Check Bill Sql    ${bill}
    Row Count Is Equal To X    ${OBC_DB_ALIAS}    ${bill_check_sql}    1
    Validate Schema    ${resp}
    Close Step
    Close Database    ${OBC_DB_ALIAS}
    Close Redis    ${OBC_REDIS_ALIAS}

2.5 用户当年存在一个结算失败的账单，通过接口查询一个未结算账单（limit为1），返回该账单数据，结算截止时间为次月16日
    Init Step
    ${interface}    Set Variable    cn.com.servyou.business.obc.facade.BillQueryFacade    #接口名
    ${method}    Set Variable    getUnsettleBill    #方法名
    ${customerId}    Get UUID    # 获取每个用例对应的customerId
    ${serviceType}    Set Variable    ${PTS_INFO['serviceTypeName']}    # 平台类型
    ${year}    Set Variable    2020    # 账单年份
    ${month}    Set Variable    1    # 账单月份
    ${limit}    Set Int Variable    1    # 账单数量
    ${settleDeadline}    Get Bill Settle Day    ${year}    ${month}    # 获取最终结算时间
    ${new_bill_sql}    Create Oec Bill    ${OBC_BILL_SELFAILED}    ${customerId}    ${year}    ${month}
    Redis Step
    Connect To Redis    ${OBC_REDIS_URL}    ${OBC_REDIS_ALIAS}
    ${redis_key}    Get Obc Unsettle Bill Key    ${customerId}    ${PTS_INFO['serviceType']}    ${limit}
    Delete Key From Redis    ${OBC_REDIS_ALIAS}    ${redis_key}
    Mysql Step
    Connect To Database    pymysql    ${OBC_DB_URL}    ${OBC_DB_ALIAS}
    Execute Sql String    ${OBC_DB_ALIAS}    DELETE from obc_fee_bill where customer_id = '${customer_id}'    ${DB_OP_TYPE_DELETE}
    Execute Sql String    ${OBC_DB_ALIAS}    ${new_bill_sql}    ${DB_OP_TYPE_DELETE}
    ${post_data}    Create Dictionary
    Set To Dictionary    ${post_data}    customerId    ${customerId}
    Set To Dictionary    ${post_data}    serviceType    ${serviceType}
    Set To Dictionary    ${post_data}    limit    ${limit}
    Doing Step
    ${resp}    Dubbo Invoke    ${OBC_ZK_ADDR}    ${interface}    ${method}    ${post_data}    ${DUBBO_PAMAR_STRING}
    Check Step
    Redis Key Should Be Exist    ${OBC_REDIS_ALIAS}    ${redis_key}
    Length Should Be    ${resp['list']}    1
    ${bill}    Set Variable    ${resp['list'][0]}
    Equal As String    ${bill['settleDeadline']}    ${settleDeadline}
    ${bill_check_sql}    Check Bill Sql    ${bill}
    Row Count Is Equal To X    ${OBC_DB_ALIAS}    ${bill_check_sql}    1
    Validate Schema    ${resp}
    Close Step
    Close Database    ${OBC_DB_ALIAS}
    Close Redis    ${OBC_REDIS_ALIAS}
